package com.zxl.live.screen.ui.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;

import com.zxl.live.tools.tools.NetUtils;

/**
 * Created by Administrator on 2017/11/14.
 */

public abstract class NetworkConnectChangedReceiver extends BroadcastReceiver {

    public void registerReceiver(Context context) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        context.registerReceiver(this, filter);
    }

    public void unregisterReceiver(Context context) {
        context.unregisterReceiver(this);
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        if (NetUtils.isNetWorkAvailable(context)) {
            onNetWorkAvailable();
        }
    }

    public abstract void onNetWorkAvailable();
}
